<template>
  <div class="detail">
    <div class="d-head">
      <van-nav-bar
        title="详情页"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
      >
        <template #right>
          <van-icon name="search" size="18" />
        </template>
      </van-nav-bar>
    </div>
    <div class="d-main">
      <div class="content" v-if="flag">
        <van-empty
          class="custom-image"
          image="https://img01.yzcdn.cn/vant/custom-empty-image.png"
          description="加载中"
        />
        <van-skeleton title :row="15" />
      </div>
      <div class="contents" v-if="!flag">
        <van-swipe :autoplay="3000">
          <van-swipe-item>
            <img :src="detail.img" />
          </van-swipe-item>
        </van-swipe>
        <p>￥:{{ detail.price }}</p>
        <h2>{{ detail.question }}？</h2>
        <van-divider
          :style="{
            color: '#1989fa',
            borderColor: '#1989fa',
            padding: '0 16px',
          }"
        >
          回答
        </van-divider>
        <p>{{ detail.answer }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      flag: true,
      detail: {},
    };
  },
  methods: {
    onClickLeft() {
      history.go(-1);
    },
  },
  computed: {
    ...mapState("Home", ["list"]),
  },
  created() {
    this.detail = this.list.filter(
      (item) => item.id == this.$route.params.id
    )[0];
    this.flag = false;
  },
};
</script>

<style lang="scss">
.custom-image .van-empty__image {
  width: 90px;
  height: 90px;
}

.van-swipe-item img {
  width: 100%;
  height: 300px;
}
</style>